new Vue({
  el: '#notebook',
  data: {
    //content: 'this is a note.',
    notes: [
      {id: 1, title: 'title1', content: 'this is content11', isActive: false, isActive1: true},
			{id: 2, title: 'title2', content: 'this is content22', isActive: false, isActive1: true},
      
    ],
      
    //记录当前被选中笔记
    selectedNote: undefined
  },
  computed: {
    preview: function() {
      return this.selectedNote ? marked(this.selectedNote.content ) :""
    }
  },
  watch:{
		notes:{
			handler:function(val, old){
				localStorage.setItem('notes', JSON.stringify(this.notes))
			},
			deep:true
			
		}
	},
	created: function(){
		this.notes = JSON.parse(localStorage.getItem('notes'))
	},

  methods: {//定义了当前vue实例所有可用的方法
    addNote:function() {
      this.notes.push({
        id: Date.now(),
        title: 'Test Note',
        content: 'test content.',
        isActive: false,
        isActive1: true
      })
      //console.log("Sssss"+this.notes)
    },
    selectNote:function(note){
      this.selectedNote = note
      
    },
    remoteNote : function(){
      const idx =this.notes.indexOf(this.selectedNote)
        if(idx !==-1){
          this.notes.splice(idx,1)
          this.selectedNote=undefined
      
        }
    },

    addNotes: function(flag){
			if(flag){
				this.selectedNote.isActive = true
        this.selectedNote.isActive1 = false
			} else{
				this.selectedNote.isActive = false
        this.selectedNote.isActive1 = true
			}
		}

    // starNote:function(note){
    //   this.selectedNote =note
    
    // },
    // starNote :function(){
    //   const idx =this.notes.indexOf(this.selectedNote)
    //   if(idx !==-1){
    //     console.log("defeat");
         
    //   }
      
    // }

  }
})